package com.ctcc.serviceImpl;

import com.ctcc.entity.Employee;
import com.ctcc.util.HttpUtil;
import com.mashape.unirest.http.JsonNode;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Peanut on 2018/2/1.
 */
@Service
public class FormDataImpl {
    Log log= LogFactory.getLog(FormDataImpl.class);
    @Autowired    HttpUtil httpUtil;

    public  String  getAllFormData(String token ,String url,JsonNode jsonNode) throws Exception {
        String result="";
        if (StringUtils.isNotEmpty(url) && StringUtils.isNotEmpty(jsonNode.toString())&& StringUtils.isNotEmpty(token)) {

            String jsonStr = httpUtil.org_yunzhijia_form(url+token , jsonNode).toString();
            if (StringUtils.isNotEmpty(jsonStr)) {
                log.info("获取接口数据成功");
            }
            JSONObject jsonObject = new JSONObject(jsonStr);
            log.info(jsonObject.get("success"));
            log.info(jsonObject.get("errorCode"));
            if ("0".equals(jsonObject.get("errorCode").toString())) {
                JSONObject jsonObjectdata = jsonObject.getJSONObject("data");
                JSONObject jsonObjectformInfo=jsonObjectdata.getJSONObject("formInfo");
                JSONObject jsonObjectwidgetMap=jsonObjectformInfo.getJSONObject("widgetMap");
                if (jsonObjectwidgetMap.length() > 0) {

                } else {
                    log.info("获取数据失败，无法导入数据");
                }
            return jsonObjectwidgetMap.toString();
            }
        }
        return  result;
    }
}
